package cn.toma.core.result;

import cn.toma.common.utils.web.IPUtil;
import cn.toma.core.exception.GlobalException;
import cn.toma.core.web.JWTUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zqx
 * @version 1.0.0
 * @ClassName BaseApi.java
 * @Description
 * @createTime 2019年08月28日 21:42:00
 */
public class BaseApi extends ResponseResult
{

	@Autowired
	private RedisTemplate<String, String> redis;


	private static final String AUTHENTICATION = "Authentication";

	/**
	 * 获取当前登录的用户
	 *
	 * @param request
	 * @return
	 */
	/*public OnlineUserVo getOnlineUser(HttpServletRequest request)
	{
		try {
			String authentication = request.getHeader(AUTHENTICATION);
			String ipAddr = IPUtil.getIpAddr(request);
			String sign = this.redis.opsForValue().get(authentication + "." + ipAddr);
			String openId = JWTUtil.getUsername(sign);
			String sessionKey = this.redis.opsForValue().get(openId + "." + ipAddr);
			Code2SessionVo code2SessionVo = new Code2SessionVo(openId, sessionKey);
			CargoMan cargoMan = cargoManService.wxIdByCargoMan(openId);
			if (cargoMan == null) {
				throw new GlobalException(CodeMsg.USER_NOT_FOUND);
			}
			OnlineUserVo onlineUserVo = new OnlineUserVo(code2SessionVo, cargoMan);
			return onlineUserVo;
		} catch (Exception e) {
			throw new GlobalException(CodeMsg.USER_NOT_FOUND);
		}
	}*/

}
